package br.mendonca.intcomp;

import java.io.File;
import java.util.LinkedList;
import java.util.List;

import br.mendonca.gmmidilib.Music;

public class MidiDirectoryCrawler implements Crawler {
	
	public List<Music> musicList = new LinkedList<Music>();

	/* (non-Javadoc)
	 * @see br.mendonca.intcomp.Crawler#crawl()
	 */
	public void crawl(File file) {
		if (file.isDirectory()) {
			for (File content : file.listFiles()) {
				crawl(content);
			}
			
		} else if (file.isFile()) {
			try {
				Music music = Music.getMusicFromFile(file);
				music.generateStatistics();
				musicList.add(music);
				System.out.println(musicList.size());
			} catch (Exception e) {
				System.out.println("Invalid file: " + file);
			}
		}
	}

}
